﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;

namespace HouseControl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        
        public MainWindow()
        {
            InitializeComponent();
             
        }

        private void btnEntrar_Click(object sender, RoutedEventArgs e)
        {
            string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Rafael\Desktop\nerds-pc\HouseControl\HouseControl\BancoDeDadosHouseControl.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            string query = "SELECT nome, login, senha FROM Funcionario";


            SqlDataReader Leitura = null;
            SqlConnection ConeccaoComOBanco = null;

            ConeccaoComOBanco = new SqlConnection(connectionString);


            if (ConeccaoComOBanco.State == ConnectionState.Closed)
            {
                ConeccaoComOBanco.Open();
            }


            SqlCommand ObjComando = new SqlCommand(query, ConeccaoComOBanco);


            Leitura = ObjComando.ExecuteReader();



            while (Leitura.Read())
            {
                if ((Leitura["login"].ToString() == LoginBox.Text) && (Leitura["senha"].ToString() == Senha_Box.Password))
                {
                    MessageBox.Show("Bem Vindo " + Leitura["nome"].ToString());
                House_Control telaInicial = new House_Control();
                telaInicial.Show();
                this.Close();
                }
                else
                {
                erro.Content = "*Login ou Senha invalido";
                }
            }

            ConeccaoComOBanco.Close();

        }

        
    }
}
